package com.example.car.ui;

import java.io.File;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import com.example.car.R;
import com.example.car.bean.ReFlush;
import com.example.car.manager.BaseActivity;
import com.example.car.manager.utils.DownLoadNet;
import com.example.car.manager.utils.HttpAll;
import com.example.car.manager.utils.HttpHelper;
import com.example.car.manager.utils.NetWorkUtil;
import com.example.car.manager.utils.OpenFiles;
//reflush
@SuppressLint("HandlerLeak")
public class WelcomeActivity extends BaseActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		 if(NetWorkUtil.GetConnect(this)!=0){
			 reflush();
		 }
		
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
//				if (!"".equals(getStringFromSharedPreferences(Constant.sp.mobile))&&null!=getStringFromSharedPreferences(Constant.sp.mobile)) {
					actionActivity(MainActivity.class, null);
					finish();
//				} else {
//				actionActivity(LoginActivity.class,null);
//					finish();
				}

//			}
		}, 1000);
	}
	
	@SuppressWarnings("unchecked")
	public void reflush(){
		new HttpAll("http://www.51wits.com/reflush.php").toJson(new HttpHelper<ReFlush>(new ReFlush()) {
			@Override
			public void delevery(boolean IsSuccuss,ReFlush task) {
				if(task.Isflu){
					System.out.println("web+++++"+task.Web);
					DownLoadNet.startDownLoad( myHandler,task.Web,"banji.apk",1);
				}else{
					return;
				}
			}
		});
	}
	public Handler myHandler=new Handler(){

		@Override
		public void handleMessage(Message msg) {
			int i=msg.arg2;
			int postion=msg.arg1;
			if(i<100){
			}else{
				File file=(File)msg.obj;
				OpenFiles.openFile(WelcomeActivity.this, (File)msg.obj);
			}
			super.handleMessage(msg);
		}
		
		
	};
}
